package com.rdxer.core.utils.search;

import com.fasterxml.jackson.annotation.JsonAlias;

import java.util.HashMap;
import java.util.Map;

/**
 * 使用方式
 * {
 * "where": {
 * "ishot": "[!=]1",
 * (默认 =)
 * "id":1000,
 * "id":"1000",
 * "id":"[=]1000",
 * (错误方式)
 * "id":["=","1000"],
 * (正确方式)
 * "id":{"opt":"=","value":"1000"},
 * <p>
 * "id":[
 * {"opt":">","value":"1000"},
 * {"opt":"<","value":"1003"}
 * ]
 * <p>
 * "id":[
 * "[>=]1000",
 * "[<]1003"
 * ]
 * <p>
 * (in 的写法)
 * <p>
 * "id":{
 * "opt":"in",
 * "value":[
 * 1335492924565229568,
 * 1000,
 * "1002"
 * ]
 * }
 * <p>
 * "id":{
 * "opt":"in",
 * "value":1000
 * }
 * <p>
 * <p>
 * <p>
 * <p>
 * },
 * "order": {
 * "id": "asc"
 * },
 * "page": 0,
 * "size":1
 * }
 */
public class SearchPara {

    public static class opt {
        public static Map<String, Object> in(Object value) {
            return Map.of("opt", "in", "value", value);
        }

        public static Map<String, Object> like(Object value) {
            return Map.of("opt", "like", "value", value);
        }

        public static Map<String, Object> isNull() {
            return Map.of("opt", "isNull", "value", "");
        }
    }


    public static Map<String, Object> makeOptValue(String opt, Object value) {
        return Map.of("opt", opt, "value", value);
    }

    private Map<String, Object> attachment;

    private Map<String, Object> where;
    private Map<String, String> order;
    @JsonAlias(value = "pageNo")
    private Integer page;
    @JsonAlias(value = "pageSize")
    private Integer size;

    public Integer defaultPage = 1;
    public Integer offsetPage = -1;
    public Integer defaultSize = 10;

    public Map<String, Object> getWhere() {
        return where == null ? where = new HashMap<>() : where;
    }

    public void setWhere(Map<String, Object> where) {
        this.where = where;
    }

    public Map<String, String> getOrder() {
        return order == null ? order = new HashMap<>() : order;
    }

    public void setOrder(Map<String, String> order) {
        this.order = order;
    }

    public Integer getPage() {
        return page == null ? page = defaultPage : page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getSize() {
        return size == null ? size = defaultSize : size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public Map<String, Object> getAttachment() {
        return attachment;
    }

    public void setAttachment(Map<String, Object> attachment) {
        this.attachment = attachment;
    }
}
